package com.qf.dao.daoImpl;

import com.qf.dao.UserDao;
import com.qf.entity.User;
import com.qf.util.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author 常肖飞先生
 * @version V1.0
 * @Project 0511_3
 * @Package com.qf.dao.daoImpl
 * @Description: 用户的daoImpl
 * @Date 2022/5/12 0:11
 */
public class UserDaoImpl implements UserDao {
   private  QueryRunner qr = new QueryRunner(DBUtil.getDateSource());
    @Override
    public User selectOne(String username, String password) {
        String sql = "select * from t_users where username = ? and password=?";
        try {
            //BeanHandler<User>(User.class)转换器  负责将查询到的结果集转换成一个对象
            return  qr.query(sql, new BeanHandler<User>(User.class), username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  null;
    }
}
